﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Venta_Factura : Global
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Obtiene el id de la venta y la forma de pago
        string idVenta = Request.Params[0].ToString();
        string formaPago = Request.Params[1].ToString();
        string captura = Request.Params[2].ToString();
        this.TraerDatosFactura(idVenta, formaPago);
    }

    private void TraerDatosFactura(string idVenta, string formaPago)
    {
        try
        {
            this.lblFormaPago.Text = formaPago;

            DataSet dts = oGDataBlocks.GetFactura(idVenta);
            if (dts.Tables[0].Rows.Count > 0)
                this.lblCliente.Text = dts.Tables[0].Rows[0]["RAZONSOCIAL"].ToString();
            else
                this.lblCliente.Text = "N/A";

            this.grdFactura.DataSource = dts.Tables[1];
            this.grdFactura.DataBind();                        

            //Calcula el total
            this.lblTotal.Text = "$0";
            if (dts.Tables[1].Compute("SUM(TOTAL)", "") != null)
                this.lblTotal.Text = "$" + dts.Tables[1].Compute("SUM(TOTAL)", "").ToString();
        }
        catch (Exception ex)
        {
            oGJS.ScriptAlert("CEDIS - Ocurrio un error en el sistema: " + ex.Message, false, Page);            
        }    
    }
}